from django.shortcuts import render

# Create your views here.

from clinicalDiseases.models import ClinicalSystemModel, ClinicalDiseasesModel, ClinicalDiseaseContentModel
from clinicalDiseases.ser import ClinicalSystemModelSerializer, ClinicalDiseasesModelSerializer, ClinicalDiseaseContentModelSerializer

from rest_framework.generics import ListAPIView
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.pagination import PageNumberPagination
from rest_framework.filters import OrderingFilter

# 分页配置
class StandardResultsSetPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    max_page_size = 100

# 排序配置
class CustomOrderingFilter(OrderingFilter):
    ordering_params = ('name', 'description')

# 临床决策 ListAPIView
class ClinicalSystemListView(ListAPIView):
    serializer_class = ClinicalSystemModelSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['name']

    def get_queryset(self):
        return ClinicalSystemModel.objects.all()

# 临床疾病 ListAPIView
class ClinicalDiseasesListView(ListAPIView):
    serializer_class = ClinicalDiseasesModelSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['name', 'description']

    def get_queryset(self):
        return ClinicalDiseasesModel.objects.all()

# 临床疾病内容 ListAPIView
class ClinicalDiseaseContentListView(ListAPIView):
    serializer_class = ClinicalDiseaseContentModelSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['content']

    def get_queryset(self):
        return ClinicalDiseaseContentModel.objects.all()